#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
using ll=long long;
const int N=1e5+10;


struct node{
	int b,c,ne;
};
int h[N],idx;
node e[N];
ll cost[N];
int vis[N];
ll cnt[N];
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;

void add(int x,int y,int z)
{
	e[idx].b=y;
	e[idx].c=z;
	e[idx].ne=h[x];
	h[x]=idx++;
}
void dijkstra()
{
	while(q.size())
	{
		auto t=q.top();
		q.pop();
		int u=t.second;
		if(vis[u])
			continue;
		vis[u]=1;
		for(int i=h[u];~i;i=e[i].ne)
		{
			int b=e[i].b;
			int c=e[i].c;
			if(!vis[b])
			{
				continue;
			}
			if(cost[c]>cost[u]+cost[b])
			{
				cost[c]=cost[u]+cost[b];
				cnt[c]=cnt[u]*cnt[b];
				q.push({cost[c],c});
			}
			else if(cost[c]==cost[u]+cost[b]){
				cnt[c]+=cnt[u]*cnt[b];
			}
		}
	}
}
int main()
{
	int n;
	cin>>n;
	memset(h,-1,sizeof(h));
	for(int i=0;i<n;i++)
	{	
		cin>>cost[i];
		cnt[i]=1;
		q.push({cost[i],i});
	}
	int x,y,z;
	while(scanf("%d%d%d",&x,&y,&z)!=EOF)
	{
		add(x,y,z);
		if(x==y)
			continue;
		add(y,x,z);
	}
	dijkstra();
	cout<<cost[0]<<' '<<cnt[0]<<endl;
	return 0;
}
